package com.sright.bcard.content.dal.dao.impl;

import com.sright.bcard.common.service.share.base.dao.BaseDAOImpl;
import com.sright.bcard.common.service.share.base.dao.BaseMapper;
import com.sright.bcard.common.service.share.dto.page.PageParamRequest;
import com.sright.bcard.content.dal.dao.UserDAO;
import com.sright.bcard.content.dal.entity.UserDO;
import com.sright.bcard.content.dal.mapper.UserDOMapper;
import com.sright.bcard.content.dal.result.EnterpriseMemberResult;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserDAOImpl extends BaseDAOImpl<UserDO> implements UserDAO {

    @Resource
    private UserDOMapper userDOMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return userDOMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<UserDO> selectByEnterpriseId(Long enterpriseId) {
        return userDOMapper.selectByEnterpriseId(enterpriseId);
    }

    @Override
    protected BaseMapper<UserDO> getObjMapper() {
        return userDOMapper;
    }

    @Override
    public List<UserDO> selectVerifyUser(Long memberId) {
        return userDOMapper.selectVerifyUser(memberId);
    }

    @Override
    public UserDO selectVerifyEnterpriseUser(Long memberId) {
        return userDOMapper.selectVerifyEnterpriseUser(memberId);
    }

    @Override
    public UserDO selectUnVerifyUser(Long id) {
        return userDOMapper.selectUnVerifyUser(id);
    }

    @Override
    public Integer unbind(Long id) {
        return userDOMapper.unbind(id);
    }

    @Override
    public  Map<Long, Long> selectUserCountGroupByEnterprise(List<Long> enterpriseIdList) {
        List<Map<String, Object>> list = userDOMapper.selectUserCountGroupByEnterprise(enterpriseIdList);
        Map<Long, Long> resultMap = new HashMap<>();
        for (Map<String, Object> map : list) {
            Long enterPriseId = (Long) map.get("enterprise_id");
            Long userNum = (Long) map.get("user_num");
            resultMap.put(enterPriseId, userNum);
        }
        return resultMap;
    }

    @Override
    public Long selectBindUserNumById(Long enterpriseId) {
        return userDOMapper.selectBindUserNumById(enterpriseId);
    }

    @Override
    public Integer selectUserCountByEnterpriseId(Long enterpriseId, String keywords) {
        return userDOMapper.selectUserCountByEnterpriseId(enterpriseId,keywords);
    }

    @Override
    public List<EnterpriseMemberResult> selectUserInfoByEnterpriseId(Long enterpriseId, String keywords, PageParamRequest paramRequest) {
        return userDOMapper.selectUserInfoByEnterpriseId(enterpriseId, keywords, paramRequest);
    }

    @Override
    public Long selectCreatedUserNum(Long enterpriseId) {
        return userDOMapper.selectCreatedUserNum(enterpriseId);
    }

    @Override
    public Long selectPersonalUserIdByOldId(Long oldPersonalUserId) {
        return userDOMapper.selectPersonalUserIdByOldId(oldPersonalUserId);
    }

    @Override
    public Long selectEnterpriserUserIdByOldId(Long oldEnterpriseUserId) {
        return userDOMapper.selectEnterpriserUserIdByOldId(oldEnterpriseUserId);
    }

    @Override
    public List<UserDO> selectAllUserByMemberId(Long memberId) {
        return userDOMapper.selectAllUserByMemberId(memberId);
    }

    @Override
    public Integer updateDelete(Long id) {
        return userDOMapper.updateDelete(id);
    }
}
